package com.twang.stock.controller.common;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.twang.stock.service.jinyan.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/stock")
@Slf4j
public class StockInfoImageController {

    @Autowired
    private CommonService commonService;
    /**
     *
     */

    @RequestMapping(value = "/hotStocks")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        String str = commonService.getValue(CommonService.HOT_STOCK_KEY);
        String[] codes = str.split(",");
        modelAndView.addObject("codes", codes);
        modelAndView.setViewName("stockinfo/stock_info_hot");
        return modelAndView;
    }

    @RequestMapping(value = "/hotStocksByKey")
    public ModelAndView hotStocksByKey(String key) {
        ModelAndView modelAndView = new ModelAndView();
        String str = commonService.getValue(key);
        if(StringUtils.isEmpty(str)){
            return null;
        }
        String[] codes = str.replace("sh", "").replace("sz", "").split(",");
        modelAndView.addObject("codes", codes);
        modelAndView.setViewName("stockinfo/stock_info_hot");
        return modelAndView;
    }


}
